<?php

namespace app\models;

use Yii;

/**
 * This is the model class for table "comment".
 *
 * @property integer $id
 * @property integer $audio_id
 * @property string $context
 * @property integer $user_id
 * @property integer $praise_num
 * @property string $ctime
 *
 * @property Audio $audio
 * @property User $user
 * @property CommentPraise[] $commentPraises
 */
class Comment extends \yii\db\ActiveRecord {
    /**
     * @inheritdoc
     */
    public static function tableName() {
        return 'comment';
    }

    /**
     * @inheritdoc
     */
    public function rules() {
        return [
            [['audio_id', 'context', 'user_id'], 'required'],
            [['audio_id', 'user_id', 'praise_num'], 'integer'],
            [['context'], 'string'],
            [['ctime'], 'safe'],
            [['audio_id'], 'exist', 'skipOnError' => true, 'targetClass' => Audio::className(), 'targetAttribute' => ['audio_id' => 'id']],
            [['user_id'], 'exist', 'skipOnError' => true, 'targetClass' => User::className(), 'targetAttribute' => ['user_id' => 'id']],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels() {
        return [
            'id' => '评论id',
            'audio_id' => '音频id',
            'context' => '评论内容',
            'user_id' => '用户id',
            'praise_num' => '点赞数 ',
            'ctime' => 'Ctime',
        ];
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getAudio() {
        return $this->hasOne(Audio::className(), ['id' => 'audio_id'])->inverseOf('comments');
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getUser() {
        return $this->hasOne(User::className(), ['id' => 'user_id'])->inverseOf('comments');
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getCommentPraises() {
        return $this->hasMany(CommentPraise::className(), ['comment_id' => 'id'])->inverseOf('comment');
    }
}
